package com.yun.blog.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yun.blog.bean.User;
import com.yun.blog.dao.UserMapper;
import com.yun.blog.service.UserService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;

/**
 * title        : UserServiceImpl
 * projectName  : dantouBlog-back
 * description  : TODO
 * author       : simple
 * date         : 2022/11/23下午8:31
 */


@Service
public class UserServiceImpl
        extends ServiceImpl<UserMapper, User>
        implements UserService {

    @Resource
    UserMapper userMapper;

    @Override
    public int updateLastLoginTimeByUserId(Integer userId) {
        return userMapper.updateLastLoginTimeByUserId(userId);
    }

    @Override
    public User getOneByUsernameAndPassword(String username, String password) {
        return userMapper.getOneByUserUsernameAndUserPassword(username, password);
    }

    @Override
    public <P extends IPage<User>> P customPage(P page, String searchText) {
        return userMapper.customPage(page, searchText);
    }

    @Override
    public User getByUserUsername(String userUsername) {
        return userMapper.getByUserUsername(userUsername);
    }

    @Override
    @Cacheable(value = "userinfo", key = "#id")
    public User getById(Serializable id) {
        return super.getById(id);
    }
}
